package com.cande.loki.exercise.algorithm;

import java.util.Arrays;

/**
 * @auther ROCK CODER
 * @DATE 2023/2/6 9:54
 * @Description 冒泡排序
 */
public class PopSort {
    public static void main(String[] args) {
        int[] arr = {5, 2, 6, 9, 1, 3, 4, 8, 7, 10};
//        quickSort(arr, 0, arr.length - 1);
        quick1(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }


    public static void swap(int [] arr,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    //快速排序
    public static void quickSort(int[] arr,int start ,int end){
        //必须要有 不然会越界
        if (start >= end)
            return;

        int i = start;
        int j =end;
        int k = arr[start];
        while (i != j){
            while (i < j && arr[j] >= k)
            {j--;}
            swap(arr, i, j);
            while (i < j && arr[i] <= k)
            {  i++;}
            swap(arr, i, j);
        }
        quickSort(arr,start ,i-1);
        quickSort(arr,i+1, end);
    }




    public static void quick1(int[]  arr,int start,int end){
        if (start>end){
            return;
        }
        int i =start;
        int j =end;
        int k = arr[start];
        while (i!=j){
            while (i<j && arr[j] >= k){
                j--;
            }
            swap1(arr,i,j);
            while (i<j && arr[i] <= k){i++;}
            swap(arr,i,j);
        }

        quick1(arr,start,i-1);
        quick1(arr,i+1,end);
    }

    public static void swap1(int[] arr,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }






















}
